import Vue from "vue";
import {MethodsType, PropsType} from '../../../types/LsRadioButtonPanel'

export default Vue.extend<unknown, MethodsType, unknown, PropsType>({
  name: "LsRadioButtonPanel",
  props: {
    value: {
      type: Object,
      default: null
    },
    buttons: {
      type: Array,
      default() {
        return []
      }
    },
    buttonUpAble: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    selectButton(item) {
      //处理选中按钮
      if (this.value) {
        if (this.value.name === item.name) {
          if (this.buttonUpAble) {
            //弹起按钮
            this.value.selected = false;
            this.$emit('input', null);
          } else
            return;
        } else {
          //替换选中按钮
          this.value.selected = false;
          item.selected = true;
          this.$emit('input', item);
        }
      } else {
        item.selected = true;
        this.$emit('input', item);
      }
    }
  }
})
